<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="../css/loginStyle.css">
    <script src="/js/jquery-3.2.1.js"></script>
</head>
<body>
<div class="jq22-container" style="padding-top:100px">
    <div class="login-wrap">
        <div class="login-html">
            <input id="tab-1" type="radio" name="tab" class="sign-in" checked><label for="tab-1" class="tab">登录</label>
            <input id="tab-2" type="radio" name="tab" class="sign-up"><label for="tab-2" class="tab">注册</label>
            <div class="login-form">
                <div class="sign-in-htm">
                    <form action="" method="">

                        <div class="group">
                            <label for="user" class="label">用户名</label>
                            <input id="user" type="text" class="input" name="username">
                        </div>
                        <div class="group">
                            <label for="pass" class="label">密码</label>
                            <input id="pass" type="password" class="input" data-type="password" name="password">
                        </div>
                        <div class="group">
                            <input id="check" type="checkbox" class="check" checked>
                            <label for="check"><span class="icon"></span>记住密码</label>
                        </div>
                        <div class="group">
                            <input type="button" id="btn" class="button" value="登录">
                        </div>
                        <div class="hr"></div>
                        <div class="foot-lnk">
                            <a href="#forgot">忘记密码?</a>
                        </div>
                    </form>

                </div>
                <div class="sign-up-htm">
                    <form action="" method="">

                        <div class="group">
                            <label for="user" class="label">用户名</label>
                            <input id="user_reg" type="text" class="input" name="username">
                        </div>
                        <div class="group">
                            <label for="pass" class="label">密码</label>
                            <input id="pass_reg" type="password" class="input" data-type="password" name="password">
                        </div>
                        <div class="group">
                            <label for="pass" class="label">确认密码</label>
                            <input id="pass_reg" type="password" class="input" data-type="password">
                        </div>
                        <div class="group">
                            <label for="pass" class="label">电话</label>
                            <input id="tel" type="text" class="input" name="tel">
                        </div>
                        <div class="group">
                            <label for="pass" class="label">地址</label>
                            <input id="address" type="text" class="input" name="address">
                        </div>

                        <div class="group">
                            <input id="reg" type="submit" class="button" value="注册">
                        </div>

                    </form>

                    <div class="hr"></div>
                    <div class="foot-lnk">
                        <label for="tab-1">Already Member?</label>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>

    $("#btn").click(function () {
        $.ajax({
            url: "/loginsubmit",
            type: "post",
            data: {
                username: $("#user").val(),
                password: $("#pass").val()
            },
            success: function (result) {
                console.log(result);
                if (result.code === "500") {
                    alert(result.msg);
                } else {
                    window.location.href = '/statetohome'
                }

            }
        })
    })


    $("#reg").click(function () {
        $.ajax({
            url: "/register",
            type: "post",
            data: {
                username: $("#user_reg").val(),
                password: $("#pass_reg").val(),
                tel: $("#tel").val(),
                address: $("#address").val()
            },
            success: function (result) {
                console.log(result);
                alert(result.msg);
                if (result.code == "1") {
                    window.location.href = 'login_reg.html'
                }
            }
        })
    })

</script>


</body>
</html>